#import "Page3.h"
#import "Page4.h"
#import "HTTPProcessor.h"
#import "UIPreferencesTableButton.h"
#import <UIKit/UIPreferencesControlTableCell.h>
#import <UIKit/UIPreferencesDeleteTableCell.h> 

@implementation Page3
- (void) createControls {
	int i;
	NSRange range = NSMakeRange(0, 10);
	UIPreferencesControlTableCell *cell = [[UIPreferencesControlTableCell alloc] init];
	sliderControl = [[UISliderControl alloc] initWithFrame:CGRectMake(50., 10., 250., 20.)];
    [sliderControl addTarget:self action:@selector(sizeSelected:) forEvents:7|64];
    [sliderControl setAllowsTickMarkValuesOnly:YES];
    [sliderControl setNumberOfTickMarks:range.length+1];
	[sliderControl setMinValue:range.location];
	[sliderControl setMaxValue:NSMaxRange(range)];
    [sliderControl setValue:range.location];
	[sliderControl setShowValue:YES];
    [sliderControl setContinuous:NO];
	[cell setControl:sliderControl];
	[cell setShowSelection:NO];
	buttons[0] = cell;

	buttons[1] = [[UIPreferencesTableButton alloc] init];
	[buttons[1] setTitle:@"Update cell"];
	[buttons[1] setAlignment:2];	
	[buttons[1] setDelegate:self];
}
 
- (void) sizeSelected:(UISliderControl*)control{
    [control setValue:floor([control value])]; 
}

- (void) buttonPressed:(NSString *)cellData {
	[processor request:[NSString stringWithFormat:@"set-D1-%f",[sliderControl value]] delegate:self];
}

- (NSString *) title {
	return @"Page3";
}

- (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)aTable cellForRow:(int)row inGroup:(int)group {
    return buttons[row];
}

 - (int)preferencesTable:(UIPreferencesTable *)aTable numberOfRowsInGroup:(int)group {
    switch (group) {
        case(0):
            return 2;
            break;
    }
}

- (void) reply:(NSString *)reply {
}
@end
